<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    /**
     * for (var i = 1; i <= 5; i++) {
          (function (i) {    //自执行函数，接收的是全局的
            setTimeout(function timer () {
                console.log(i);  //setTimeout 是异步所以最后才执行
            }, i * 1000) //一秒执行一次timer
        })(i)  //1-6
    }
    console.log(i);  //全局变量，只有for循环执行完才会往下执行，执行完for之后i成6
     **/
    var obj1 = { a: 1, b: 2, c: 3, d: { e: 4 } }
    var obj2 = { ...obj1 }  //只能拷贝一层，大于一层都是浅拷贝
    obj1.a = 2
    obj1.d.e = 5
    console.log(obj2);


    //执行顺序：2 3 4 1
    // Promise是微任务,setTimeout是宏任务 先微后宏，所以先执行Promise里面，再执行setTimeout
    setTimeout(function () {
        console.log(1);
    }, 0)
    new Promise(function (resolve) {
        console.log(2);
        resolve()
        console.log(3);
    }).then(function () {
        console.log(4);
    })

    // 去重
    const arr = [12, 24, 37, 24, 49, 49, 55, 68]
    let arr1 = new Set(arr)
    // let arr1 = []
    arr.forEach(item => {
        if (arr.indexOf(item) === -1) { //indexOf 没找到数组里面的每一项就返回-1，就不包含，可以添加进去
            arr1.push(item)
        }
    })
    console.log(arr1);
</script>

</html>